Skip to content

fix: Fix collision prospect checking to be fully reliable#3905

Merged
spydon merged 2 commits intomainfrom
luan.fix-collision-prospect-hashing
Apr 20, 2026
Merged

fix: Fix collision prospect checking to be fully reliable#3905
spydon merged 2 commits intomainfrom
luan.fix-collision-prospect-hashing

Conversation

@luanpotter
Copy link
Copy Markdown
Member

@luanpotter luanpotter commented Apr 19, 2026

Description

Fix collision prospect checking to be fully reliable.

Turns out there is still a high-percent chance of hash collisions even with #3864 on our tests, causing CI flakyness.

This completely bypasses the issue by making the code collision-resistent to begin with. This is orthogonal to improving hashing collision rate.

At first I added my own implementation of Set but then realize that we can just use Dart's set, if we are clever about it. It already handles collisions elegantly (i.e. with no performance penalty if there are no collisions), by using a flat array with index fallbacks. Every recover check pays one hash and at least one identity check which are very cheap.

We just need to implement hashCode and equals, the hash can use the existing approximation, and the equals can use the unordered identity check.

This bulks up the pool implementation to hide the "mutable" view over CollisionProspect, which I made a immutable first-class citizen. No one can mutate the prospect other than the pool, that owns the lifecycle.

At the end of the day there was no reason for these sets to be a map keyed on hashcode. That is just a poor-mans set!

I dare say it is impossible for the CI to flake now :P

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

@luanpotter luanpotter force-pushed the luan.fix-collision-prospect-hashing branch from 74b5ae1 to 51ace92 Compare April 19, 2026 19:28
@luanpotter luanpotter marked this pull request as ready for review April 19, 2026 19:43
@luanpotter luanpotter requested a review from spydon April 19, 2026 19:43
Copy link
Copy Markdown
Member

@spydon spydon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@spydon spydon enabled auto-merge (squash) April 20, 2026 09:42
@spydon spydon merged commit d5a21a7 into main Apr 20, 2026
75 checks passed
@spydon spydon deleted the luan.fix-collision-prospect-hashing branch April 20, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants